<template>
	<view class="">
		<view class="" style="padding-top: 80px;">
			<view class="">
				<!-- 		<template v-if="settings.is_login_set == 1 ">
					<view class="flex j-c">
						<view class="flex a-c j-c by1 bg-white" style="border: solid 6rpx #F5F5F5;">
							<view class="  flex j-c a-c by1"
								:class="currenindex==0?'login_option_active zhuti_bg1':'login_option'" @tap.stop="on_mode(0)">
								密码登录
							</view>
							<view v-if="settings.is_sms==1" class="login flex j-c a-c by1"
								:class="currenindex==1?'login_option_active zhuti_bg1':'login_option'" @tap.stop="on_mode(1)">
								验证码登录
							</view>
						</view>
					</view>
					<view class="p3 " style="padding-top: 40px;">
						<bmInput bicon="&#xe67b;" v-model="tel" placeholder="请输入账号/手机号"></bmInput>
						<block v-if="currenindex === 0">
							<view class="pt5"> </view>
							<bmInput type='password' bicon="&#xe6c0;" v-model="password" placeholder="请输入密码"></bmInput>
							<view v-if="settings.reg_img_code==1" class="pt5">
								<bmInput @get_imgCode='get_imgCode' bicon="&#xe67a;" v-model="v_code" placeholder="请输入图形验证码"
									:codeimg="settings.code_img_rand"></bmInput>
							</view>
						</block>
						<block v-if="currenindex === 1">
							<view class="pt5" v-if="settings.sms_img_code==1">
								<bmInput @get_imgCode='get_imgCode' bicon="&#xe67a;" v-model="v_code" placeholder="请输入图形验证码"
									:codeimg="settings.code_img_rand"></bmInput>
							</view>
							<view class="pt5">
								<bmInput @getCode='getCode' bicon="&#xe67a;" v-model="smscode" placeholder="请输入短信验证码"
									:tips="tips"></bmInput>
							</view>
						</block>
						<view class="flex j-c pt8">
							<view @click="is_login" class="flex j-c a-c by1  cff  zhuti_bg1" style="width: 88%;height: 40px;">
								登录
							</view>
						</view>
						<view class="flex j-c pt5">
							<view class="f30" v-if="settings.is_account==1" @click="user_reg">注册账号 </view>
						</view>
					</view>
				</template> -->
				<!-- <template v-if="settings.is_login_set == 0 "> -->
				<template>
					<view class="flex j-c a-c">
						<view class="t_c">
							<view class="flex j-c a-c">
								<view>
									<image style="width: 120rpx;height: 120rpx;" src="@/static/icon/weixin.png">
									</image>
								</view>
							</view>
							<view class="" style="height: 40px;"> </view>
							<view @click="on_login" class="flex j-c a-c b_y cff but_login">
								<text>微信授权登录</text>
							</view>
							<view class="" style="height: 30px;">
							</view>
						</view>
					</view>
				</template>
				<!-- 条款 -->
				<view class="flex a-c j-c  " style="padding-top: 20rpx;">
					<view @click="on_agr" class="b_y flex a-c j-c"
						style="width: 30rpx;height: 30rpx;border: solid 2rpx #A9A9A9;">
						<text v-if="agr" class="f26 " style="color: #A9A9A9;">✓</text>
					</view>
					<text class="f30  ml1  " style="color: #A9A9A9;">我已阅读并同意</text>
					<text class="f30 " style="color: #1E90FF;" @click="article_view(10)">
						隐私条款
					</text>
					<text style="color: #A9A9A9;">和</text>
					<text class="f30 " style="color: #1E90FF;" @click="article_view(9)">
						用户协议
					</text>
				</view>
				<view class="pt8">
					<!-- #ifndef APP -->
					<view v-if="settings.is_sms == 1 || settings.is_account == 1" class="flex a-c j-c"
						style="padding-bottom: 10px;">
						<text class="c_7">其他登录方式</text>
					</view>
					<!-- #endif -->
				</view>
			</view>
		</view>
		<!-- <userTelBang ref="userTelBang" :is_information="is_information"> -->
		</userTelBang>
	</view>
</template>

<script>
	import WXBizDataCrypt from "@/common/WXBizDataCrypt.js"
	// import bmInput from '@/page1/component/bm_input.vue'
	// import userTelBang from './user_tel_bang.vue'
	export default {
		components: {
			// bmInput
			// userTelBang
		},
		data() {
			return {
				currenindex: 0,
				tips: '获取验证码',
				password: '',
				tel: '',
				smscode: '',
				agr: false,
				settings: {},
				v_code: '',
				user: {},
				avatarUrl: '',
				userName: '',
				is_information: false,
				set_tel: '授权手机号',
				platform: '',
				plugin_set: {},
				app_login_wx: 0
			}
		},
		// onShow() {
		// 	// #ifdef H5
		// 	this.h5_weixin_login();
		// 	// #endif
		// 	// #ifdef MP-WEIXIN
		// 	this.getCode_wx()
		// 	// #endif
		// },
		onLoad() {
			// this.wx_mp_login = 0;
			// this.platform = uni.getSystemInfoSync().platform;
			// this.encryptedData = '';
			// this.init();
		},
		methods: {
			init() { //查询用户信息
				var that = this;
				this.Htpp.user_info().then(res => {
					this.$module.sm(res, 2, ret => {
						let data = ret
						console.log(data,'获取用户数据')
						that.user = data.data.user
						that.business = data.data.business
						uni.setStorageSync('user', data.data.user)
						uni.setStorageSync('business', data.data.business)
						// that.getuser(data.data.user.id)
					})
				})
			},
			// getuser(id) { //查询用户信息
			// 	var that = this;
			// 	this.Htpp.user_msg(id).then(ret => {
			// 		this.$module.sm(ret.data, 2, ret => {
			// 			let data = JSON.parse(ret)
			// 			console.log(data,213131)
			// 		})
			// 	})
			// },
			on_login(e) { //登录同意条款
				if (!this.agr) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: "none"
					});
					return;
				}
				this.on_login_ajax(e);
			},
			agr_but() {
				if (this.plugin_set.wx_login_sms == 1) {
					uni.showToast({
						title: '请先同意协议',
						icon: 'error',
						duration: 1000
					})
					return
				}
				this.settings.is_login_set = 1;
				this.currenindex = 1
			},
			// getPhoneNumberHandler(e) {
			// 	console.log("e: " + JSON.stringify(e));
			// },
			// baidu_phonenumber(e) {
			// 	console.log("e: " + JSON.stringify(e));
			// },
			// getPhoneNumberali(e) {
			// 	let that = this;
			// 	my.getPhoneNumber({
			// 		success: (res) => {
			// 			let encryptedData = res.response;
			// 			this.Htpp.post('/banmi.php/Alilogin/login', 'app', {
			// 				token: false,
			// 				datalist: {
			// 					encryptedData: encryptedData
			// 				}
			// 			}).then(ret => {

			// 			})
			// 		},
			// 		fail: (res) => {
			// 			console.log(res);
			// 		},
			// 	});
			// },
			// bindGetUserInfo(e) {
			// 	console.log(e.detail.userInfo)
			// },
			// getPhoneNumber(e) {
			// 	let requestParams = {
			// 		errMsg: e.detail.errMsg,
			// 		agr: this.agr,
			// 		wx_code: this.wx_code,
			// 	};
			// 	this.Htpp.getPhoneNumber(requestParams).then(ret => {
			// 		this.wx_tel(e.detail.encryptedData, e.detail.iv, ret)
			// 	})
			// },
			// getCode_wx() {
			// 	this.Htpp.mp_wx_code().then(ret => {
			// 		this.wx_code = ret;
			// 	})
			// },
			on_login_tel(currenindex) {
				this.settings.is_login_set = 1;
				this.currenindex = currenindex
			},
			// user_reg(){
			// 	uni.navigateTo({
			// 		url: '/pages/banmi/user_reg'
			// 	})
			// },
			get_imgCode() {
				let data = {
					code_img: this.settings.code_img,
				};
				this.Htpp.get_imgCode(data).then(ret => {
					this.settings.code_img_rand = ret.code_img_rand;
					this.v_id = ret.v_id;
				})
			},
			on_login_ajax(e) { //微信登录
				var that = this;
				uni.showLoading({
					title: '正在连接...'
				})
				// let appid = this.settings['apppid'];
				// var http = window.location.protocol;
				// var com = window.location.host;
				// var url = encodeURIComponent(link);
				// window.location.href =
				// 	`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;

				//微信小程序授权登录
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						that.mp_weixin_ajax(loginRes.code);
					}
				});
			},

			//微信小程序登录
			mp_weixin_ajax(code) {
				uni.removeStorageSync('user');
				uni.removeStorageSync('business');
				uni.removeStorageSync('Token');
				let requestParams = {
					inviteUserId:uni.getStorageSync('inviteUserId')||'',
					code: code
				}
				this.Htpp.mp_wx_login(requestParams).then(ret => {
					this.init();
					uni.switchTab({
						url: '/pages/index/index'
					})
					//获取用户信息
				})
			},
			article_view(index) {
				uni.navigateTo({
					url: '/pages/banmi/article_view?id=' + index
				})
			},

			on_mode(index) {
				this.currenindex = index
			},
			//完善资料
			// basic_information(user) {
			// 	this.is_information = true;
			// 	user.wx_code = this.wx_code;
			// 	this.user = user;
			// 	let that = this;
			// 	this.$refs.userTelBang.zi_init(user, that.settings, that.plugin_set)
			// },
			on_agr() {
				this.agr = !this.agr
			},
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff;
	}

	.pt8 {
		padding-top: 80rpx;
	}

	.pt5 {
		padding-top: 80rpx;
	}

	.but_width {
		width: 90rpx;
	}

	button::after {
		border: none;
	}

	button {
		padding: 0;
		background-color: transparent;

	}

	.login_icon {
		width: 70rpx;
		height: 70rpx;
	}

	.but_login {
		width: 600rpx;
		height: 80rpx;
		background-color: #1DC069;
	}

	.refreshIcon {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
		border: solid 2rpx #32CD32;
	}

	.userName {
		padding: 10rpx 10rpx 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		.weui-input {
			padding: 20rpx;
			border: solid 2rpx #32CD32;
			border-radius: 10rpx;
		}
	}

	.btn {
		width: 100%;
		display: flex;
		justify-content: center;

		.btn-sub {
			width: 670rpx;
			height: 80rpx;
			background: #32CD32;
			border-radius: 45rpx;
			font-size: 36rpx;
			color: #fff;
		}
	}


	.login_option_active {

		width: 120px;
		height: 40px;
		color: #fff;
		font-size: 30rpx;
	}

	.login_option {
		background-color: #fff;
		width: 120px;
		height: 40px;
		color: #333;
		font-size: 30rpx;
	}
</style>